home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 019 / keymap_test / con_io.c next >
C/C++ Source or Header  |  1995-03-17  |  3KB  |  95 lines

  1. /******  con_io.c  *********/
  2.  
  3. /************************************************************************
  4.  *
  5.  *                    Console Device functions
  6.  *
  7.  ************************************************************************/
  8.  
  9.  
  10. #include "keymap_test.h"
  11.  
  12. /* These functions are taken directly from the console.device chapter
  13.  * in the Amiga V1.1 ROM KERNEL manual.  See manual for documentation. */
  14.  
  15.  
  16. /* Open a console device */
  17.       int
  18. OpenConsole(writerequest,readrequest,window)
  19.       struct IOStdReq *writerequest;
  20.       struct IOStdReq *readrequest;
  21.       struct Window *window;
  22.       {
  23.             int error; 
  24.             writerequest->io_Data = (APTR) window;
  25.             writerequest->io_Length = sizeof(*window);
  26.             error = OpenDevice("console.device", 0, writerequest, 0);
  27.             readrequest->io_Device = writerequest->io_Device;
  28.             readrequest->io_Unit   = writerequest->io_Unit;
  29.                   /* clone required parts of the request */
  30.             return(error);
  31.       }
  32.  
  33. /* Output a single character to a specified console */ 
  34.  
  35.       int
  36. ConPutChar(request,character)
  37.       struct IOStdReq *request;
  38.       char character;
  39.       {
  40.             request->io_Command = CMD_WRITE;
  41.             request->io_Data = (APTR)&character;
  42.             request->io_Length = 1;
  43.             DoIO(request);
  44.             return(0);
  45.       }
  46.  
  47. /* Output a NULL-terminated string of characters to a console */ 
  48.  
  49.       int
  50. ConPutStr(request,string)
  51.       struct IOStdReq *request;
  52.       char *string;
  53.       {
  54.             request->io_Command = CMD_WRITE;
  55.             request->io_Data = (APTR)string;
  56.             request->io_Length = -1;
  57.             DoIO(request);
  58.             return(0);
  59.       }
  60.  
  61.       /* queue up a read request to a console */
  62.  
  63.       int
  64. QueueRead(request,whereto)
  65.       struct IOStdReq *request;
  66.       char *whereto;
  67.       {
  68.             request->io_Command = CMD_READ;
  69.             request->io_Data = (APTR)whereto;
  70.             request->io_Length = 1;
  71.             SendIO(request);
  72.             return(0);
  73.       }
  74.  
  75. /* see if there is a character to read.  If none, don't wait,
  76.  * come back with a value of 0 
  77.  */
  78.         int  
  79. ConMayGetChar (request, requestPort, whereto)
  80.         struct IOStdReq *request;
  81.         struct MsgPort  *requestPort;
  82.         UBYTE *whereto;
  83.         {
  84.                 register int temp;
  85.  
  86.                 if (CheckIO (request) == FALSE)
  87.                         return (0);     /* no char typed in */
  88.                 
  89.                 GetMsg (requestPort);
  90.                 temp = *whereto;
  91.  
  92.                 QueueRead (request, whereto);
  93.                 return (temp);
  94.         }
  95.